<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class ad_model extends MY_Model
{

	 public function getAdList($type=0)
    {
        $where = " AND type = 0";
        if($type === 1)
        {
            $where = " and type=1";
        }
        $sql = "SELECT * FROM blues_advertisement  WHERE isDel=0 {$where}  ORDER BY addtime desc";
        $query = $this->db->query($sql);

        return $query->result_array();
    }

     //编辑
    public function editAd($id,$data = array()){
        if($id){
            $this->db->where("id",$id);
            $res = $this->db->update("blues_advertisement",$data);
        }else{
            $res = $this->db->insert("blues_advertisement",$data);
        }
        return $res;
    }

    public function delAd($id){
        $this->db->where("id",$id);
        $data = array(
            'isDel'=>1
        );
        $res = $this->db->update("blues_advertisement",$data);
        return $res;
    }

     //根据id获取广告信息
    public function getAdInfobyID($id){
        $this->db->where("id",$id);
        $query = $this->db->get("blues_advertisement");
        return $query->row_array();
    }

    public function editStatus($data = array()){

        $this->db->where("id",$data['id']);
        if($data['type'] == "onlinestatus"){
            $data = array(
                'onlinestatus'=>$data['onlinestatus']
            );
        }
        if($data['type'] == "isDel"){
            $data = array(
                'isDel'=>1
            );
        }

        $res = $this->db->update("blues_advertisement",$data);
        return $res;
    }

}


